﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using CommonTypes.Server.Operations;
using Server.Model;

namespace Server.Menus
{
    public partial class OperationsForm : Form
    {
        private readonly ServerData _serverData;

        public OperationsForm( ServerData serverData )
        {
            _serverData = serverData;
            InitializeComponent( );
        }

        private void button1_Click( object sender, EventArgs e )
        {
            Hide( );
        }

        private static String identifyOperation( Operation op )
        {
            if( op is AddOperation )
                return "AddOperation";
            if( op is RemoveOperation )
                return "RemoveOperation";
            if( op is TicketGeneration )
                return "TicketGeneration";
            return "Unknown";
        }

        private void OperationsForm_Activated( object sender, EventArgs e )
        {
            listBox1.Items.Clear( );
            foreach( KeyValuePair<long, Operation> item in _serverData.Operations )
            {
                StringBuilder sb = new StringBuilder( );
                sb.Append( String.Format( "{0}->{2} at {1}", item.Key, item.Value.LogicalNumber, identifyOperation( item.Value ) ) );
                listBox1.Items.Add( sb.ToString( ) );
            }
        }
    }
}